#include "BatteryState.h"

//获取英文名称（主要供调试用）
QString CBatteryState::GetName(int iBatteryState)
{
    QString ret = "unknown";
    if (IsForbidCharge(iBatteryState)) { //0x1111(十4369)禁充
        ret = "forbid_charge";
    } else if (IsForbidDischarge(iBatteryState)) { //0x2222(十8738)禁放
        ret = "forbid_discharge";
    } else if (IsAlarm(iBatteryState)) { //0x5555(十21845)告警
        ret = "alarm";
    } else if (IsFault(iBatteryState)) { //0xAAAA(十43690)故障
        ret = "fault";
    } else if (IsNormal(iBatteryState)) { //0xBBBB(十48059)正常
        ret = "normal";
    } else if (IsWarn(iBatteryState)) { //0xCCCC(十52428)预警
        ret = "warn";
    }

    return ret;
}

//获取中文utf8(主要供界面显示)
//static
QString CBatteryState::GetUtf8(int iBatteryState)
{
    QString ret = "\xE6\x9C\xAA\xE7\x9F\xA5"; //未知

    if (IsForbidCharge(iBatteryState)) { //0x1111(十4369)禁充
        ret = "\xe7\xa6\x81\xe5\x85\x85";
    } else if (IsForbidDischarge(iBatteryState)) { //0x2222(十8738)禁放
        ret = "\xe7\xa6\x81\xe6\x94\xbe";
    } else if (IsAlarm(iBatteryState)) { //0x5555(十21845)告警
        ret = "\xe5\x91\x8a\xe8\xad\xa6";
    } else if (IsFault(iBatteryState)) { //0xAAAA(十43690)故障
        ret = "\xe6\x95\x85\xe9\x9a\x9c";
    } else if (IsNormal(iBatteryState)) { //0xBBBB(十48059)正常
        ret = "\xe6\xad\xa3\xe5\xb8\xb8";
    } else if (IsWarn(iBatteryState)) { //0xCCCC(十52428)预警
        ret = "\xE9\xA2\x84\xE8\xAD\xA6";
    }

    return ret;
}

//是不是禁止状态
bool CBatteryState::IsForbid(int iBatteryState)
{
    return CBatteryState::IsForbidCharge(iBatteryState) || CBatteryState::IsForbidDischarge(iBatteryState);
}

//是不是禁充状态
bool CBatteryState::IsForbidCharge(int iBatteryState)
{
    return FORBID_CHARGE == iBatteryState;
}

//是不是禁访状态
bool CBatteryState::IsForbidDischarge(int iBatteryState)
{
    return FORBID_DISCHARGE == iBatteryState;
}

//是不是告警状态
bool CBatteryState::IsAlarm(int iBatteryState)
{
    return ALARM == iBatteryState;
}

//是不是故障状态
bool CBatteryState::IsFault(int iBatteryState)
{
    return FAULT == iBatteryState;
}

//是不是正常状态
bool CBatteryState::IsNormal(int iBatteryState)
{
    return NORMAL == iBatteryState;
}

//是不是预警状态
bool CBatteryState::IsWarn(int iBatteryState)
{
    return WARN == iBatteryState;
}
